#ifndef __GLESHardwareVertexBuffer_H__
#define __GLESHardwareVertexBuffer_H__

#include "U2GLESPreRequest.h"
#include "U2HardwareVertexBuffer.h"


U2EG_NAMESPACE_BEGIN


/// Specialisation of U2HardwareVertexBuffer for OpenGL ES
class _U2GLESShare GLESHardwareVertexBuffer : public U2HardwareVertexBuffer
{
private:
    GLuint mBufferId;
    // Scratch buffer handling
    bool mLockedToScratch;
    size_t mScratchOffset;
    size_t mScratchSize;
    void* mScratchPtr;
    bool mScratchUploadOnUnlock;

protected:
    /** See U2HardwareBuffer. */
    void* lockImpl(size_t offset, size_t length, LockOptions options);
    /** See U2HardwareBuffer. */
    void unlockImpl(void);

public:
    GLESHardwareVertexBuffer(U2HardwareBufferManagerBase* mgr, size_t vertexSize, size_t numVertices,
                           U2HardwareBuffer::Usage usage, bool useShadowBuffer);
    virtual ~GLESHardwareVertexBuffer();

    /** See U2HardwareBuffer. */
    void readData(size_t offset, size_t length, void* pDest);

    /** See U2HardwareBuffer. */
    void writeData(size_t offset, size_t length, 
                   const void* pSource, bool discardWholeBuffer = false);

    /** See U2HardwareBuffer. */
    void _updateFromShadow(void);

    GLuint getGLBufferId(void) const { return mBufferId; }
};


U2EG_NAMESPACE_END

#endif
